//
// Created by LH on 2017/9/3.
//

#include <iostream>

using namespace std;
int e[6][6];  //邻接矩阵
int book[50];
int queue[1000];
int head = 0, tail = 0;
int sum = 0;
int n, m, start, end;
int main()
{

    cin >> n >> m >> start >> ::end;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            if (i == j)
                e[i][j] = 0;
            else
                e[i][j] = 6;
        }
    }
    for (int t = 1; t <= m; ++t) {
        int a, b;
        cin >> a >> b;
        e[a][b] = 1;
        e[b][a] = 1;
    }

    queue[tail] = start;
    book[start] = 1;
    tail++;
    sum++;
    while (head < tail)
    {

        for (int l = 1; l <= n; ++l) {
            if (e[queue[head]][l] == 1 && !book[l])
            {
                if (l == ::end) {
                    cout << sum;
                }
                queue[tail] = l;
                book[l] = 1;
                tail++;
            }
        }
        //book[queue[head]] = 0;
        sum++;
        head++;
    }
    return 0;
}

/*
5 7 1 5
1 2
1 3
2 3
2 4
3 4
3 5
4 5
*/